package chapter19_Enum;

import chapter20_Annotations.ExtractInterface;

import javax.xml.ws.soap.MTOM;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Set;
import java.util.TreeSet;

/**
 * Date: 2019/6/18
 * Time: 15:46
 * User: Driss.
 * Description：
 */
//enumerated/Reflection.java
//Analyzing enums using reflection

enum Explore{HERE,THERE}

public class Reflection {

    public static Set<String> analyze(Class<?> enumClass){
        System.out.println("---- Analyzing " + enumClass + " -------");

        System.out.println("Interfaces:");
        for (Type t : enumClass.getGenericInterfaces())
            System.out.println(t);

        System.out.println("Base : " + enumClass.getSuperclass());
        System.out.println("Methods:");


        TreeSet<String> methods = new TreeSet<String>();
        for (Method m : enumClass.getMethods())
            methods.add(m.getName());

        System.out.println(methods);
        return methods;
    }

    public static void main(String[] args) throws ClassNotFoundException {

        Set<String> exploreMethods = analyze(Explore.class);
        Set<String> enumMethods = analyze(Enum.class);

        System.out.println("Explore.containsAll(Enum)? " + exploreMethods.containsAll(enumMethods));
        System.out.println("Explore.removeAll(Enum): " + exploreMethods.removeAll(enumMethods));

        System.out.println(exploreMethods);

        //Decompile the code for the enum
    }

}
